Repository navigation
fix(db): harden RLS — close anon exposure and public-row mutation - #196
Merged
Merged
Conversation
The users RLS SELECT policy used `OR true`, so any browser holding the public Supabase anon key could read the whole users table (email, reader prefs, location, stats). Restrict direct reads to the owner and add a public_user_profiles view exposing only profile-safe columns for public rendering. Also make donations SELECT owner-only (public transparency already comes from v_transparency_monthly, not raw rows carrying Stripe ids and donor messages), pin search_path on the SECURITY DEFINER auth trigger, and enable RLS (deny-all, service_role only) on the internal search_queries, affiliate_clicks, system_jobs and affiliate_retailers tables.
reading_lists, reading_list_books and annotations used a single FOR ALL policy whose USING clause allowed public rows. Since DELETE only evaluates USING, any user could delete a public reading list or non-private annotation, and UPDATE could reassign ownership. Split each into a public FOR SELECT policy plus owner-only INSERT/UPDATE/DELETE policies. Verified with a simulated non-owner role: public read allowed, delete/steal blocked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexte
Vérifié en conditions réelles (Postgres + pgvector local, rôles
anonet non-propriétaire simulés).packages/utils/src/supabase.tsexpose unbrowserClient()avec la clé anon → l'API PostgREST anon est ouverte côté navigateur, donc les policies RLS sont la seule barrière.Lot 1 — exposition en lecture via anon
userslisible publiquement :users_self_selectutilisaitUSING (id = current_auth_uid() OR true). LeOR truerendait toute la table (email, reader_prefs, location, stats) lisible par tout client anon. → SELECT propriétaire uniquement + vuepublic_user_profiles(colonnes profil sûres, sans email).donations:OR anonymous = FALSEexposait les dons non anonymes (ids Stripe, messages). → SELECT propriétaire uniquement ; transparence publique viav_transparency_monthly.search_pathépinglé àpublic, pg_temp.search_queries,affiliate_clicks,system_jobs,affiliate_retailers) : RLS deny-all, accès serveur via service_role.Lot 2 — mutation de lignes publiques (audit de suivi)
reading_lists,reading_list_booksetannotationsétaient en une seule policyFOR ALLdont leUSINGautorisait les lignes publiques. Comme DELETE n'évalue que USING, n'importe qui pouvait supprimer une liste de lecture publique ou une annotation non privée, et UPDATE pouvait réassigner l'ownership. → Split en une policyFOR SELECTpublique + INSERT/UPDATE/DELETE propriétaire uniquement.Validation (rôle simulé)
usersbrut lu par anonpublic_user_profilespar anonemailinexistantedonationsbrut par anon (don non anonyme seedé)Schéma rechargé sans erreur (
ON_ERROR_STOP=1). Couvre le fond réel des PR bots fermées (#188, #195) avec un correctif unique testé.